<template>
  <div>
    <van-nav-bar :title="comment.reply_count ? comment.reply_count +'条回复':'暂无回复' ">
      <template #left>
        <van-icon name="cross" @click="$emit('click-popup')" />
      </template>
    </van-nav-bar>
    <div class='scroll-wrap'>
      <!-- 当前评论组件 -->
      <CommentItem :comment='comment'></CommentItem>
      <!-- 全部回复 -->
      <van-cell title='全部回复'></van-cell>
      <ArticleCommon type='c' :source='comment.com_id' :list='list'></ArticleCommon>
    </div>
    <div class="post-warp">
      <van-button round @click='isShowReplyPost=true'>评论</van-button>
    </div>
    <!-- 回复评论弹层 -->
    <van-popup v-model='isShowReplyPost' position='bottom'>
      <!-- 评论内容 -->
      <ArticlePost @onPostSuccess='onPostSuccess' :target="comment.com_id" :artId='$route.params.id'>
      </ArticlePost>
    </van-popup>
  </div>
</template>

<script>
// 回复评论
import ArticlePost from './article-post.vue'
// 评论组件
import CommentItem from '@/components/comment-item'
// 全部回复评论
import ArticleCommon from './article-common.vue'
export default {
  data () {
    return {
      // 文章评论数据
      list: [],
      // 回复评论显示
      isShowReplyPost: false
    }
  },
  props: {
    // 父传子评论列表数据
    comment: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 回复评论
    onPostSuccess (e) {
      console.log(e)
      this.isShowReplyPost = true
      this.list.unshift(e.new_obj)
      this.comment.reply_count++
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {
    CommentItem,
    ArticleCommon,
    ArticlePost
  },
  created () {

  },
  mounted () { }
}
</script>

<style scoped lang='less'>
.scroll-wrap {
  position: fixed;
  top: 92px;
  bottom: 102px;
  width: 100%;
  overflow-y: scroll;
}
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  .van-button {
    width: 640px;
    height: 80px;
    background-color: red;
  }
}
</style>
